import { 
    fetch,
    ModifyAck,
    DeleteAck
} from './service';
  
const Model = {
    namespace: 'setupandack',
    state: {
    },

    effects: {
        *fetch({ payload }, { call }) {
            const response = yield call(fetch, payload)
            if (!response.List) {
                return { status: 500 }
            }
            const data = []
            // eslint-disable-next-line array-callback-return
            response.List.map(item =>{
                data.push({
                    key: item.Id,
                    id: item.Id,
                    // name: `c01:${item.Ack.split(",")[0]},c02:${item.Ack.split(",")[1]},c03:${item.Ack.split(",")[2]}`,
                    name: item.Ack,
                    currentAckTime: item.Time,
                    range: item.Scope.split(","),
                    // status: item.Dacl,
                    status: 1
                })
            })
            return {
                status: 200,
                totalPageSize: response.Page.TotalCount,
                data,
            }
        },

        *modifyAck({ payload }, { call, put }) {
            const data = {
                Id: payload.Id,
                Ack: payload.ack.join(","),
                Time: payload.day.toString(),
                Scope: payload.Scope.join(",")
            }
            const response = yield call(ModifyAck, data);
            return {
                status: 200, data: response
            }

        },
        *deleteAck({ payload }, { call, put }) {
            const response = yield call(DeleteAck, payload)
            return {
                status: 200, data: response
            }
        }
    },

    reducers: {
        
    },
}
export default Model;
  